using CodePlex.TfsLibrary.RepositoryWebSvc;

namespace CodePlex.CodePlexClientLibrary
{
    public abstract class ListCommand : AuthenticatedCommand
    {
        bool recursive;
        int revision = -1;
        bool verbose;

        [Option("recursive", "act recursively on directories", ShortName = "e")]
        public bool Recursive
        {
            get { return recursive; }
            set { recursive = value; }
        }

        [Option("revision", "get a specific change set", ShortName = "r")]
        public int Revision
        {
            get { return revision; }
            set { revision = value; }
        }

        [Option("verbose", "display verbose information", ShortName = "v")]
        public bool Verbose
        {
            get { return verbose; }
            set { verbose = value; }
        }

        public override void Execute()
        {
            string tfsUrl;
            string serverPath;
            VersionSpec version;

            if (revision < 0)
                version = VersionSpec.Latest;
            else
                version = VersionSpec.FromChangeset(revision);

            GetListParameters(out tfsUrl, out serverPath);

            new ListConsoleView(Engine).Run(tfsUrl, serverPath, Recursive, version, Verbose);
        }

        protected abstract void GetListParameters(out string tfsUrl,
                                                  out string serverPath);
    }
}